package com.sskj.lib.ui.activity;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.ImageView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.facebook.stetho.inspector.protocol.module.Worker;
import com.hjq.toast.ToastUtils;
import com.just.agentweb.AgentWeb;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.FileCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ImageUtil;
import com.sskj.common.util.PermissionTipUtil;
import com.sskj.common.util.RxSchedulersHelper;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.BaseHttpConfig;
import com.sskj.lib.MusicService;
import com.sskj.lib.R;
import com.sskj.lib.R2;
import com.sskj.lib.RConfig;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;
import com.tbruyelle.rxpermissions2.RxPermissions;

import java.io.File;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Flowable;

public class SplashActivity extends Activity {
    @BindView(R2.id.webView)
    WebView webView;
    @BindView(R2.id.ivBg)
    ImageView ivBg;


    private AgentWeb agentWeb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setNavigationBarColor();
        setContentView(R.layout.lib_activity_splash);
        ButterKnife.bind(this);

        agentWeb = AgentWeb.with(this)
                .setAgentWebParent(webView, new ViewGroup.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .createAgentWeb()
                .ready()
                .go(BaseHttpConfig.TONGXIN_URL);

        ImageUtil.setOriginImage(R.mipmap.app_splash, ivBg);
//        Intent serviceIntent = new Intent(SplashActivity.this, MusicService.class);
//        startService(serviceIntent);
        Flowable.timer(4, TimeUnit.SECONDS).compose(RxSchedulersHelper.transformer()).subscribe(aLong -> {
            if (SPUtil.get(SPConfig.LOGIN, false)) {
                ARouter.getInstance().build(RConfig.APP_MAIN).navigation();
            } else {
                ARouter.getInstance().build(RConfig.APP_LOGIN).navigation();
            }
            finish();
        });
    }


    private void setNavigationBarColor() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // Translucent navigation bar
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }
}
